

import UIKit

class SecondPageController: UIViewController {

    
    @IBOutlet weak var btnReturnToFirstPage: UIButton!
    @IBOutlet weak var btnConvert: UIButton!
    
    @IBOutlet weak var convertText: UITextField!
    
    @IBAction func returnToFirstPage(_ sender: UIButton) {
        self.dismiss(animated: true, completion: nil)
    }
    @IBAction func convertText(_ sender: UIButton) {
        let str = convertText.text?.trimmingCharacters(in: NSCharacterSet.whitespaces);
        var result = "";
        for temp in (str?.characters)!{
            if(temp == ",")
            {
                let index = result.index(result.endIndex,offsetBy:-1);
                let s = result.substring(from:index).uppercased();
                let formerStr = result.substring(to:index);
                result = formerStr + s + " ";
            }
            else if(temp == ";")
            {
                let index = result.index(result.endIndex,offsetBy:-1);
                let s = result.substring(from:index).lowercased();
                let formerStr = result.substring(to:index);
                result = formerStr + s + " ";
            }
            else
            {
                result.append(temp);
            }
        }
        convertText.text = result;
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
        btnReturnToFirstPage.layer.cornerRadius = 4.0;
        btnReturnToFirstPage.layer.masksToBounds = true;
        btnConvert.layer.cornerRadius = 4.0;
        btnConvert.layer.masksToBounds = true;
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}
